package com.wu.apiuserzk.controller;

import com.wu.common.entity.ResultData;
import com.wu.common.entity.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author whx
 * @date 2021/7/9
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Value("${server.port}")
    String port;

    @GetMapping("/list")
    public ResultData list() throws InterruptedException {
//        Thread.sleep(5000);
        List<User> list = new ArrayList<>(2);
        User user1 = new User(1,"name1_"+port,"userName1","123");
        User user2 = new User(2,"name2_"+port,"userName2","123");
        list.add(user1);
        list.add(user2);
        return new ResultData().SUCCESS(list);
    }

    @GetMapping("/hi")
    public String hi(){
        return "hi";
    }

    @GetMapping("/page")
    public ResultData page(@RequestParam("id")Integer id,@RequestParam("name")String name){
        return new ResultData().SUCCESS(new User(id,name,"userName",port));
    }

    @PostMapping("/getById")
    public ResultData getById(@RequestParam("id") Integer id){
        User user = new User(id,"name"+id,"userName"+id,port);
        return new ResultData().SUCCESS(user);
    }

    @PostMapping("/getOne")
    public ResultData getOne(){
        User user = new User(1,"name1","userName1",port);
        return new ResultData().SUCCESS(user);
    }

    @PostMapping("/getUser")
    public ResultData getUser(@RequestBody User user){
        user.setPassword(port);
        return new ResultData().SUCCESS(user);
    }


}
